<template>
  <vol-box
    :lazy="true"
    v-model="model"
    title="生产领用单"
    :height="400"
    :width="1200"
    :padding="5"
    :onModelClose="onModelClose"
  >
    <produceUse ref="produceUse"></produceUse>
    <template #footer>
      <div>
        <el-button type="primary" size="small" @click="detailOnSelect"
          >确认</el-button
        >
      </div>
    </template>
  </vol-box>
</template>
  
  <script>
import VolBox from "@/components/basic/VolBox.vue";
import produceUse from "@/views/produceinfo/produce_use/q_produce_use.vue";
export default {
  components: {
    "vol-box": VolBox,
    produceUse,
  },
  data() {
    return {
      model: false,
    };
  },
  methods: {
    onModelClose() {
      this.$refs.produceUse.searchFormFields.Voucher_sub = null;
      this.$refs.produceUse.searchFormFields.Goods_sub = null;
      this.$refs.produceUse.searchFormFields.Goods_name = null;
      this.$refs.produceUse.searchFormFields.Proposer = null;
      this.$refs.produceUse.searchFormFields.Production_state = null;
      this.$refs.produceUse.searchFormFields.AuditStatus = null;
    },
    async open() {
      this.model = true;
      let setIntervalTiem = setInterval(() => {
        if (this.$refs.produceUse) {
          clearInterval(setIntervalTiem);
          this.$refs.produceUse.searchFormFields.AuditStatus = "1";
          this.$refs.produceUse.searchFormFields.Production_state = "1";
          this.$refs.produceUse.$refs.grid.search();
        }
      }, 100);
    },
    async detailOnSelect() {
      let selectionRows = this.$refs.produceUse.$refs.grid.getSelectRows();
      if (selectionRows.length == 1) {
        //  判断审核未通过数据，后期放开
        let AuditStatusSome = selectionRows.some(
          (item) => item.AuditStatus != 1
        );
        if (AuditStatusSome) {
          if (this.messageError) {
            this.messageError.close();
          }
          this.messageError = this.$message.error("请勿选择审核未通过单据");
          return;
        }
        let ProductionStateSome = selectionRows.some(
          (item) => item.Production_state != 1
        );
        if (ProductionStateSome) {
          if (this.messageError) {
            this.messageError.close();
          }
          this.messageError = this.$message.error("请选择生产中单据");
          return;
        }
        this.$emit("parentCall", ($parent) => {
          $parent.editFormFields.Produce_use = selectionRows[0].Produce_use;
          $parent.editFormFields.Produce_use_voucher_sub =
            selectionRows[0].Voucher_sub;
          $parent.editFormFields.Goods_sub = selectionRows[0].Goods_sub;
          $parent.editFormFields.Goods_name = selectionRows[0].Goods_name;
          $parent.editFormFields.Proposer = selectionRows[0].Proposer;
          $parent.editFormFields.WHSE_no = selectionRows[0].WHSE_no;
          $parent.editFormFields.WHSE_jg = selectionRows[0].WHSE_jg;
        });
        this.onModelClose();
        return (this.model = false);
      } else {
        if (this.messageError) {
          this.messageError.close();
        }
        this.messageError = this.$message.error("请选择一条领用单");
      }
    },
  },
};
</script>
  
  <style>
</style>